<?php 
namespace Com\Mvc\Controller;

use Zend\View\Model\ViewModel;
use Zend\Mvc\Controller\AbstractActionController;
use Com\Mvc\Factory\ServiceLocator\ServiceLocatorFactory;
class BaseController extends AbstractActionController{
	
	protected $serviceManager = null;
	
	function __construct(){
		$this->serviceManager = ServiceLocatorFactory::getInstance();
	}
	
	/**
	 * 获得已经加载的命名空间
	 * 测试使用
	 * @return array
	 */
	final public function getNamespaces(){
		
		$name = \Zend\Loader\AutoloaderFactory::getRegisteredAutoloaders();
		$standname = $name[\Zend\Loader\AutoloaderFactory::STANDARD_AUTOLOADER];
		$namespace = $standname->namespaces;
		return $namespace;
	}
	
	/**
	 * 异步返回数据
	 * @param int $statusCode
	 * @param string $message
	 * @param mixed $data
	 */
	final public function ajaxReturn($statusCode,$message,$data=null) {
	
		$return = array();	
		$return['statusCode'] = $statusCode;	
		$return['message']  = $message;
	
		if($data!==null){
			$return['data'] = $data;
		}
	
		exit ( json_encode ( $return ) );
	
	}

    /**
	 * 打印函数
	 * @param mixed $var
	 * @param boolean $flag
	 */
	final public function p($var,$flag=TRUE){
		if(is_scalar($var)){
			echo $var;
		}else{
			echo "<pre>";
			var_dump($var);
		}
		if($flag){
			exit;
		}
	}
}
?>